package dome1;

import java.util.Scanner;

public class Test{
    private static final String UserName = "yeye";
    private static final String PassWord = "123456";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try{
            System.out.print("请输入用户名：");
            String username = scanner.nextLine();
            System.out.print("请输入密码：");
            String password = scanner.nextLine();
            Login(username,password);
            System.out.println("登入成功");
        }catch (UserNameErrorException e){
            e.printStackTrace();
        }catch (PassWordErrorException e){
            e.printStackTrace();
        }finally {
            scanner.close();
        }
    }

    public static void Login(String username, String password) throws UserNameErrorException,PassWordErrorException{
        if(!username.equals(UserName)){
            throw new UserNameErrorException("用户名错误，发生异常...");
        }

        if (!password.equals(PassWord)){
            throw new PassWordErrorException("密码错误，发生异常...");
        }
    }
}

